﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppCommerciaux.Entity
{
    public partial class commandeclient
    {

        public decimal? GetTotalTTC()
        {
            decimal? result = 0;
            using (Entity.liv3Entities1 dc = new Entity.liv3Entities1())
            {
                List<lignecommandeclient> listlignecom = dc.lignecommandeclient.Where(lcc => lcc.id_commandeclient == this.id).ToList();
                foreach (lignecommandeclient lcc in listlignecom)
                {
                    result += (lcc.puHT * lcc.quantite) + ((lcc.puHT * lcc.quantite * lcc.tauxTva)/100);
                }
            }
            if (ListNewLigneCommande != null)
                {
                    foreach (lignecommandeclient lcc in ListNewLigneCommande)
                    {
                        result += (lcc.puHT * lcc.quantite) + ((lcc.puHT * lcc.quantite * lcc.tauxTva) / 100);
                    }
                }

            return result;
        }

        public decimal? GetTotalHT()
        {
            decimal? result = 0;
            using (Entity.liv3Entities1 dc = new Entity.liv3Entities1())
            {
                List<lignecommandeclient> listlignecom = dc.lignecommandeclient.Where(lcc => lcc.id_commandeclient == this.id).ToList();
                foreach (lignecommandeclient lcc in listlignecom)
                {
                    result += lcc.puHT * lcc.quantite;
                }
            }
            if (ListNewLigneCommande != null)
            {
                foreach (lignecommandeclient lcc in ListNewLigneCommande)
                {
                    result += lcc.puHT * lcc.quantite;
                }
            }

            return result;
        }

        private List<lignecommandeclient> _listNewLigneCommande;
        public List<lignecommandeclient> ListNewLigneCommande
        {
            get {
                if (_listNewLigneCommande == null)
                {
                    _listNewLigneCommande = new List<lignecommandeclient>();
                }
                return _listNewLigneCommande; }
            set
            {
                if (_listNewLigneCommande != value)
                {
                    _listNewLigneCommande = value;
                }
            }
        }

    }
}
